from sqlalchemy import Column, String, Text, text, INTEGER, Boolean, CHAR, SMALLINT, TIMESTAMP

from models.base import Base


class SystemLogOperate(Base):
    """系统操作日志实体"""
    __tablename__ = 'system_log_operate'
    __table_args__ = {
        'comment': '系统操作日志表',
    }

    id = Column(INTEGER(), primary_key=True, comment='主键')
    admin_id = Column(INTEGER(), nullable=False, server_default=text('0'), comment='操作人ID')
    type = Column(String(30), nullable=False, server_default='', comment='请求类型: GET/POST/PUT')
    title = Column(String(30), server_default='', comment='操作标题')
    ip = Column(String(30), nullable=False, server_default='', comment='请求IP')
    url = Column(String(200), nullable=False, server_default='', comment='请求接口')
    method = Column(String(200), nullable=False, server_default='', comment='请求方法')
    args = Column(Text, comment='请求参数')
    error = Column(Text, comment='错误信息')
    status = Column(SMALLINT(), nullable=False, server_default=text('1'),
                    comment='执行状态: 1=成功, 2=失败')
    start_time = Column(INTEGER(), nullable=False, server_default=text('0'), comment='开始时间')
    end_time = Column(INTEGER(), nullable=False, server_default=text('0'), comment='结束时间')
    task_time = Column(INTEGER(), nullable=False, server_default=text('0'), comment='执行耗时')
    create_time = Column(TIMESTAMP, comment='创建时间')
